<?php
require_once('lib/event.php');
?>
<script src="pages_admin/adherents/adherents.js" type="text/javascript"></script>
<h3>Réponses d'un événement</h3>
<?php
$id = intval($_GET['id']);

if(isset($_GET['toggle'])) {
	$toggle = intval($_GET['toggle']);

	$previous_decision = event_get_decision($id, $toggle);
	$new_decision = $previous_decision == 'Y' ? 'N' : 'Y';

	event_update_decision($id, $toggle, $new_decision);

	$url_page = explode('&toggle', $_SERVER['REQUEST_URI']);
	$_SERVER['REQUEST_URI'] = $url_page[0];
}

$event = event_get_by_id($id);
if ($event == NULL) {
	?>
	<p class="error">Cet événement n'existe pas</p>
	<?php
}
else {
	echo 'Nombre de membres ayant confirmé leur venue à l\'événement « <strong>'.$event['name'].'</strong> » : <strong>'.$event['count_join'].'</strong>';

	$members = event_members($id);
	if ($row = mysql_fetch_assoc($members)) {
		?>
		<table class="dataTable">
			<thead>
			<tr>
				<th>Nom</th>
				<th>Prénom</th>
				<th>Décision</th>
				<th>Date décision</th>
				<th>Détails membre</th>
			</tr>
			</thead>
			<tbody>
			<?php
			do {
				switch ($row['decision']) {
					case 'Y':
						$decision = '<span style="color: green;">Participe</span>';
						break;
					case 'N':
						$decision = '<span style="color: red;">Ne participe pas</span>';
						break;
					default:
						$decision = '<strong>Décision invalide !</strong>';
						break;
				}
				echo '
				<tr>
					<td>'.$row['name'].'</td>
					<td>'.$row['firstname'].'</td>
					<td>'.$decision.'</td>
					<td>'.date_to_str($row['date']).'</td>
					<td>
						<a href="javascript:details('.$row['id'].');" title="Voir les détails">'.icon_tag('magnifier').'</a>';
						if ($_SESSION['status_code'] == 'ADMIN') {
							echo '
							<a href="'.$_SERVER['REQUEST_URI'].'&toggle='.$row['id'].'" title="Inverser décision">'.icon_tag('arrow_switch').'</a>';
						}
						echo '
					</td>
				</tr>
				';
			} while ($row = mysql_fetch_assoc($members));

			?>
			</tbody>
		</table>
		<p class="back"><a href="?p=club&amp;r=events">Revenir à la liste des événements</a></p>
		<?php
	}
}
